/** 查询得到一个对象显示在页面中
 *
 * <div id="vue_det">
 *	  <h1>site : {{site}}</h1>
 *    <h1>url : {{url}}</h1>
 *	  <h1>{{details()}}</h1>
 *	</div>
 *  var encryptdata = {
 *  	 	id : '#vue_det',
 *	 		url : 'http://172.25.230.1:8080/fucai/1.jsp',
 *	 		parameter : {
 *		        id: 100
 *		    }
 *	 	}
 *   	var getInfoObject=new GetInfoObject();
 *  	getInfoObject.load(encryptdata);
 */
function GetInfoObject() {

	this.load = function(encryptdata) {
		$(encryptdata.id).hide();
		api.ajax({
			url : serverIP + encryptdata.url,
			method : 'post',
			data : {
				values : encryptdata.parameter
			}
		}, function(ret, err) {
			if (ret) {
				var vm = new Vue({
					el : encryptdata.id,
					data : {
						object:ret.data
					},
					methods : {
						details : function() {
							return this.site + " - 学的不仅是技术，更是梦想！";
						}
					},
					mounted : function() {
						$(encryptdata.id).show();
					}
				})
			} else {
				api.alert({
					msg : JSON.stringify(err)
				});
			}
		});  
	}
}

/** 查询数据带分页
 * <div id="app">
 *	  <ul>
 *	    <li v-for="value in object">
 *	   		{{ value.site }}-{{ value.url }}-{{ value.alexa }}
 *	    </li>
 *	  </ul>
 *	</div>
 *   var encryptdata = {
 *		id : '#app',
 *		url : 'http://172.25.230.1:8080/fucai/1.jsp',
 *		parameter : {
 *	        id: 100
 *	    }
 *	 }
 *	var getInfoPaging=new GetInfoPaging();
 *	getInfoPaging.init(encryptdata);//初始化
 *  getInfoPaging.load();//加载数据
 *  getInfoPaging.paging();//分页并加载数据,下拉进行分页
 *
 * v-on:click="openDetail($index)"
 *
 * 你点击的索引为: {{ click }}
 */
function GetInfoPaging() {

	var vm;
	var encryptdata;
	var isHidden = 1;
	var setting;
	var myScroll;
	//初始化参数
	this.init = function(encryptdata) {

		this.encryptdata = encryptdata;
		var st = this.setting;

		vm = new Vue({
			el : encryptdata.id,
			data : {
				object : [],
			},
			methods : {
				openDetail : function(id, url) {
					api.openWin({
						name : url,
						url : url,
						bounces : false,
						vScrollBarEnabled : false,
						animation : {
							type : 'push',
							subType : "from_right",
							duration : "500"
						},
						pageParam : {
							"id" : id,
						}
					});
				}
			}
		})
	}
	//加载数据
	this.load = function() {
		var id = this.encryptdata.id;
		var top = this.myScroll;
		if (isHidden) {
			$(id).hide();
		}
		//alert(JSON.stringify(this.encryptdata.parameter))
		api.ajax({
			url : serverIP + this.encryptdata.url,
			method : 'post',
			dataType : 'json',
			data : {
				values : this.encryptdata.parameter
			}
		}, function(ret, err) {
			if (ret) {
				//vm.object = vm.object.concat(ret);
				for (var i = 0; i < ret.length; i++) {
				// vm.object.splice(i,1,);
				 vm.$set(vm.object, i, ret[i])
					//vm.object.push(ret[i]);
				}
				console.log("1"+vm.object)
				window.onload = setTimeout(function() {
					window.scrollTo(0, top);
					//修改500为指定高度
				}, 800);
				if (ret.length == 0) {
					$(".nomore").show();
				}
				if (isHidden) {
					$(id).show();
				}
			} else {
				api.alert({
					msg : JSON.stringify(err)
				});
			}

		});
	}
	//设置分页、下拉刷新、上拉分页加载数据
	this.paging = function() {
		var pagingThis = this;

		//下拉刷新
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : 'rgba(0,0,0,0)',
			textColor : '#666',
			textDown : '下拉刷新',
			textUp : '释放刷新'
		}, function(ret, err) {
			pagingThis.myScroll = 0
			pagingThis.clearVue();
			pagingThis.load();
			api.refreshHeaderLoadDone();
		});
		//上拉分页请求加载下一页页面
		api.addEventListener({
			name : 'scrolltobottom',
			extra : {
				threshold : 0
			}
		}, function(ret, err) {
			pagingThis.encryptdata.parameter.pageNo += 1;
			pagingThis.myScroll = pagingThis.getScrollTop()
			pagingThis.load();
		});
	}
	//清空vue所有数据
	this.clearVue = function() {
	
	}
	this.setIsHidden = function() {
		this.isHidden = 0
	}
	this.setSetting = function(details) {
		this.setting = details;
	}
	//取窗口滚动条高度
	this.getScrollTop = function() {
		var scrollTop = 0;
		if (document.documentElement && document.documentElement.scrollTop) {
			scrollTop = document.documentElement.scrollTop;
		} else if (document.body) {
			scrollTop = document.body.scrollTop;
		}
		return scrollTop;
	}
}

/** 跳转页面
 *
 */
function openDetail(url) {
	api.openWin({
		name : url,
		url : url,
		bounces : false,
		vScrollBarEnabled : false,
		animation : {
			type : 'push',
			subType : "from_right",
			duration : "500"
		}
	});
}

function openDetail(url,paraam) {
	api.openWin({
		name : url,
		url : url,
		bounces : false,
		vScrollBarEnabled : false,
		animation : {
			type : 'push',
			subType : "from_right",
			duration : "500"
		},
		pageParam : paraam
	});
}

/** 政策信息按照类型查询并且跳转
 * @param {Object} typeId 类型id
 */
function detailPolicyService(typeId) {
	api.openWin({
		name : "policyService/policy_interpretation_window",
		url : "policyService/policy_interpretation_window.html",
		bounces : false,
		vScrollBarEnabled : false,
		animation : {
			type : 'push',
			subType : "from_right",
			duration : "500"
		},
		pageParam : {
			"typeId" : typeId,
		}
	});
}

/** 政策解读信息按照类型查询并且跳转
 * @param {Object} typeId 类型id
 */
function detailReleaseService(typeId) {
	api.openWin({
		name : "release/policy_release_window",
		url : "release/policy_release_window.html",
		bounces : false,
		vScrollBarEnabled : false,
		animation : {
			type : 'push',
			subType : "from_right",
			duration : "500"
		},
		pageParam : {
			"typeId" : typeId,
		}
	});
}